package cn.z2huo.demo.kafka.spring.retry.nonblock.support;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
@Component
public class Cluster1ProducerListener implements ProducerListener<String, String> {

    @Override
    public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
        log.info("kafka send Message success, topic is {}, partition is {}, timestamp is {}, record value is {}",
                recordMetadata.topic(), recordMetadata.partition(), recordMetadata.timestamp(), producerRecord.value()
        );
    }

    @Override
    public void onError(ProducerRecord producerRecord, RecordMetadata recordMetadata, Exception exception) {
        log.error("test-topic kafka send Message error, topic is {}, partition is {}, timestamp is {}, record value is {}",
                producerRecord.topic(), producerRecord.partition(), producerRecord.timestamp(), producerRecord.value(), exception
        );
    }

}
